﻿using OP20.Models;

namespace OP20.ViewModels
{
    public class ST01CyManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST01CyManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;
            InitParam();
        }
        #region 事件
        private void InitParam()
        {
            IsCheck01 = InductorParam_Global.aByPass[0];
            IsCheck02 = InductorParam_Global.aByPass[1];
            IsCheck03 = InductorParam_Global.aByPass[2];
            IsCheck04 = InductorParam_Global.aByPass[3];
            IsCheck05 = InductorParam_Global.aByPass[4];
            IsCheck06 = InductorParam_Global.aByPass[7];
            IsCheck07 = InductorParam_Global.aByPass[15];
            CylinderDelay.DelayTime13 = InductorParam_Global.aDelay[0];
            CylinderDelay.DelayTime14 = InductorParam_Global.aDelay[1];
            CylinderDelay.DelayTime15 = InductorParam_Global.aDelay[2];
            CylinderDelay.DelayTime16 = InductorParam_Global.aDelay[3];
            CylinderDelay.DelayTime17 = InductorParam_Global.aDelay[4];
            CylinderDelay.DelayTime18 = InductorParam_Global.aDelay[7];
            CylinderDelay.DelayTime19 = InductorParam_Global.aDelay[15];

            CylinderDelay.DelayTime01 = ST01GKCarrySpinCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime02 = ST01GKCarryUpDownCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime03 = ST01WeighUpDownCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime04 = ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime05 = ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime06 = ST01CarryInhaleCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime07 = ST01GKCarrySpinCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime08 = ST01GKCarryUpDownCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime09 = ST01WeighUpDownCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime10 = ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime11 = ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime12 = ST01CarryInhaleCy.cylinderPCToPLC_Global.tGoTime;

            checkModel.IsQGOriginCheck01 = ST01GKCarrySpinCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck02 = ST01GKCarryUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck03 = ST01WeighUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck04 = ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck05 = ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck06 = ST01CarryInhaleCy.cylinderPCToPLC_Global.bOrgSenByPass;

            checkModel.IsQGWorkCheck01 = ST01GKCarrySpinCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck02 = ST01GKCarryUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck03 = ST01WeighUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck04 = ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck05 = ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck06 = ST01CarryInhaleCy.cylinderPCToPLC_Global.bWorkSenByPass;

        }
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST01");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST01View, param);
        }



        /// <summary>
        /// 气缸感应器屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderPinBiCommand;
        public DelegateCommand<string> CylinderPinBiCommand =>
            _CylinderPinBiCommand ?? (_CylinderPinBiCommand = new DelegateCommand<string>(ExecuteCylinderPinBiCommand));

        void ExecuteCylinderPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST1管壳搬运旋转气缸原点":
                    ST01GKCarrySpinCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;

                case "ST1管壳搬运上下气缸原点":
                    ST01GKCarryUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;

                case "ST1称重上下气缸原点":
                    ST01WeighUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = true;

                    break;
                case "ST1管壳称重夹爪原点":
                    ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass = true;

                    break;
                case "ST1管壳上料错位气缸原点":
                    ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.bOrgSenByPass = true;

                    break;
                case "ST1管壳搬运真空吸原点":
                    ST01CarryInhaleCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;


                case "ST1管壳搬运旋转气缸动点":
                    ST01GKCarrySpinCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;

                case "ST1管壳搬运上下气缸动点":
                    ST01GKCarryUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;

                case "ST1称重上下气缸动点":
                    ST01WeighUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = true;

                    break;
                case "ST1管壳称重夹爪动点":
                    ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass = true;

                    break;
                case "ST1管壳上料错位气缸动点":
                    ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.bWorkSenByPass = true;

                    break;
                case "ST1管壳搬运真空吸动点":
                    ST01CarryInhaleCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;

                case "ST1管壳到位感应":
                    InductorParam_Global.aByPass[0] = true;
                    break;
                case "ST1上料直振缺料检测":
                    InductorParam_Global.aByPass[1] = true;
                    break;
                case "ST1上料圆振缺料检测":
                    InductorParam_Global.aByPass[2] = true;
                    break;
                case "ST1直振1满料感应":
                    InductorParam_Global.aByPass[3] = true;
                    break;
                case "ST1直振2满料感应":
                    InductorParam_Global.aByPass[4] = true;
                    break;
                case "ST1转盘穴位检测":
                    InductorParam_Global.aByPass[7] = true;
                    break;
                case "ST1管壳真空吸":
                    InductorParam_Global.aByPass[15] = true;
                    break;
              
                default:
                    break;
            }
        }

        /// <summary>
        /// 气缸感应器解除屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderUnPinBiCommand;
        public DelegateCommand<string> CylinderUnPinBiCommand =>
            _CylinderUnPinBiCommand ?? (_CylinderUnPinBiCommand = new DelegateCommand<string>(ExecuteCylinderUnPinBiCommand));

        void ExecuteCylinderUnPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST1管壳搬运旋转气缸原点":
                    ST01GKCarrySpinCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;

                case "ST1管壳搬运上下气缸原点":
                    ST01GKCarryUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;

                case "ST1称重上下气缸原点":
                    ST01WeighUpDownCy.cylinderPCToPLC_Global.bOrgSenByPass = false;

                    break;
                case "ST1管壳称重夹爪原点":
                    ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass = false;

                    break;
                case "ST1管壳上料错位气缸原点":
                    ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.bOrgSenByPass = false;

                    break;
                case "ST1管壳搬运真空吸原点":
                    ST01CarryInhaleCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;


                case "ST1管壳搬运旋转气缸动点":
                    ST01GKCarrySpinCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;

                case "ST1管壳搬运上下气缸动点":
                    ST01GKCarryUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;

                case "ST1称重上下气缸动点":
                    ST01WeighUpDownCy.cylinderPCToPLC_Global.bWorkSenByPass = false;

                    break;
                case "ST1管壳称重夹爪动点":
                    ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass = false;

                    break;
                case "ST1管壳上料错位气缸动点":
                    ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.bWorkSenByPass = false;

                    break;
                case "ST1管壳搬运真空吸动点":
                    ST01CarryInhaleCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;

                case "ST1管壳到位感应":
                    InductorParam_Global.aByPass[0] = false;
                    break;
                case "ST1上料直振缺料检测":
                    InductorParam_Global.aByPass[1] = false;
                    break;
                case "ST1上料圆振缺料检测":
                    InductorParam_Global.aByPass[2] = false;
                    break;
                case "ST1直振1满料感应":
                    InductorParam_Global.aByPass[3] = false;
                    break;
                case "ST1直振2满料感应":
                    InductorParam_Global.aByPass[4] = false;
                    break;
                case "ST1转盘穴位检测":
                    InductorParam_Global.aByPass[7] = false;
                    break;
                case "ST1管壳真空吸":
                    InductorParam_Global.aByPass[15] = false;
                    break;
                default:
                    break;
            }
        }





        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {

                case "DelayTime01":
                    ST01GKCarrySpinCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime01;
                    break;
                case "DelayTime02":
                    ST01GKCarryUpDownCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime02;
                    break;
                case "DelayTime03":
                    ST01WeighUpDownCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime03;
                    break;
                case "DelayTime04":
                    ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime04;
                    break;
                case "DelayTime05":
                    ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime05;
                    break;
                case "DelayTime06":
                    ST01CarryInhaleCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime06;
                    break;

                case "DelayTime07":
                    ST01GKCarrySpinCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime07;
                    break;
                case "DelayTime08":
                    ST01GKCarryUpDownCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime08;
                    break;
                case "DelayTime09":
                    ST01WeighUpDownCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime09;
                    break;
                case "DelayTime10":
                    ST01WeighJiaZhuaCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime10;
                    break;
                case "DelayTime11":
                    ST01LoadMaterialChuoWeiCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime11;
                    break;
                case "DelayTime12":
                    ST01CarryInhaleCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime12;
                    break;


                case "DelayTime13":
                    InductorParam_Global.aDelay[0] = CylinderDelay.DelayTime13;
                    break;
                case "DelayTime14":
                    InductorParam_Global.aDelay[1] = CylinderDelay.DelayTime14;
                    break;
                case "DelayTime15":
                    InductorParam_Global.aDelay[2] = CylinderDelay.DelayTime15;

                    break;
                case "DelayTime16":
                    InductorParam_Global.aDelay[3] = CylinderDelay.DelayTime16;

                    break;
                case "DelayTime17":
                    InductorParam_Global.aDelay[4] = CylinderDelay.DelayTime17;

                    break;
                case "DelayTime18":
                    InductorParam_Global.aDelay[7] = CylinderDelay.DelayTime18;

                    break;
                case "DelayTime19":
                    InductorParam_Global.aDelay[15] = CylinderDelay.DelayTime19;

                    break;


                default:
                    break;
            }
        }

        #endregion


        #region 属性  

        private CylinderDelayModel _cylinderDelay;
        public CylinderDelayModel CylinderDelay
        {
            get { return _cylinderDelay ?? (_cylinderDelay = new CylinderDelayModel()); }
            set { SetProperty(ref _cylinderDelay, value); }
        }


        private bool _IsCheck01;
        public bool IsCheck01
        {
            get { return _IsCheck01; }
            set { SetProperty(ref _IsCheck01, value); }
        }


        private bool _IsCheck02;
        public bool IsCheck02
        {
            get { return _IsCheck02; }
            set { SetProperty(ref _IsCheck02, value); }
        }

        private bool _IsCheck03;
        public bool IsCheck03
        {
            get { return _IsCheck03; }
            set { SetProperty(ref _IsCheck03, value); }
        }

        private bool _IsCheck04;
        public bool IsCheck04
        {
            get { return _IsCheck04; }
            set { SetProperty(ref _IsCheck04, value); }
        }

        private bool _IsCheck05;
        public bool IsCheck05
        {
            get { return _IsCheck05; }
            set { SetProperty(ref _IsCheck05, value); }
        }


        private bool _IsCheck06;
        public bool IsCheck06
        {
            get { return _IsCheck06; }
            set { SetProperty(ref _IsCheck06, value); }
        }

        private bool _IsCheck07;
        public bool IsCheck07
        {
            get { return _IsCheck07; }
            set { SetProperty(ref _IsCheck07, value); }
        }


        private CylinderSensorCheckModel _checkModel;
        public CylinderSensorCheckModel checkModel
        {
            get { return _checkModel ?? (_checkModel = new CylinderSensorCheckModel()); }
            set { SetProperty(ref _checkModel, value); }
        }
        #endregion
    }
}
